﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class admin_ViewOrderDetails : System.Web.UI.Page
{
    DataTable dt;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            LoadOrder();   
        }      

        if (Session["adminlogin"] == null)
        {
            Response.Redirect("adminlogin.aspx");
        }
    }
    public void LoadOrder()
    {
        int ID = Convert.ToInt32(Request.QueryString["ID"]);
        DataSet2TableAdapters.tbl_orderTableAdapter da = new DataSet2TableAdapters.tbl_orderTableAdapter();
        DataSet2 ds2 = new DataSet2();
        da.FillBy(ds2.tbl_order, ID);

        dt = new DataTable();
        dt = ds2.Tables["tbl_order"];
        DetailsViewOrder.DataSource = dt;
        DetailsViewOrder.DataBind();
    }


    protected void DetailsViewOrder_ModeChanging(object sender, DetailsViewModeEventArgs e)
    {
        DetailsViewOrder.ChangeMode(DetailsViewMode.Edit);

        //cach #
        
        if (e.CancelingEdit)
        {
            DetailsViewOrder.ChangeMode(DetailsViewMode.ReadOnly);
        }

    }
    protected void DetailsViewOrder_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
    {
        TextBox TextBoxCode = (TextBox)DetailsViewOrder.FindControl("TextBoxCode");
        TextBox TextBoxDate = (TextBox)DetailsViewOrder.FindControl("TextBoxDate");
        DropDownList ddlist = (DropDownList)DetailsViewOrder.FindControl("DropDownListStatus");
        TextBox TextBoxSFname = (TextBox)DetailsViewOrder.FindControl("TextBoxSFname");
        TextBox TextBoxSLname = (TextBox)DetailsViewOrder.FindControl("TextBoxSLname");
        TextBox TextBoxSemail = (TextBox)DetailsViewOrder.FindControl("TextBoxSemail");
        TextBox TextBoxSAddress = (TextBox)DetailsViewOrder.FindControl("TextBoxSAddress");
        TextBox TextBoxSphone = (TextBox)DetailsViewOrder.FindControl("TextBoxSphone");
        TextBox TextBoxSState = (TextBox)DetailsViewOrder.FindControl("TextBoxSState");
        TextBox TextBoxScity = (TextBox)DetailsViewOrder.FindControl("TextBoxScity");
        TextBox TextBoxSzipcode = (TextBox)DetailsViewOrder.FindControl("TextBoxSzipcode");
        TextBox TextBoxPMname = (TextBox)DetailsViewOrder.FindControl("TextBoxPMname");
        DropDownList ddlistCardtype = (DropDownList)DetailsViewOrder.FindControl("PayDropDownListCard");
        TextBox TextBoxPMcardnum = (TextBox)DetailsViewOrder.FindControl("TextBoxPMcardnum");
        TextBox TextBoxPMverinum = (TextBox)DetailsViewOrder.FindControl("TextBoxPMverinum");
        TextBox TextBoxPMexpri = (TextBox)DetailsViewOrder.FindControl("TextBoxPMexpri");
        TextBox TextBoxquantity = (TextBox)DetailsViewOrder.FindControl("TextBoxquantity");
        TextBox Texttotalprice = (TextBox)DetailsViewOrder.FindControl("Texttotalprice");
        int ID = Convert.ToInt32(DetailsViewOrder.DataKey["od_id"]);
        Order objOrder = new Order();
        objOrder.OdCode = TextBoxCode.Text;
        objOrder.OrderDate = Convert.ToDateTime(TextBoxDate.Text);
        objOrder.Status = ddlist.SelectedItem.Text;
        objOrder.ShipFname = TextBoxSFname.Text;
        objOrder.ShipLname = TextBoxSLname.Text;
        objOrder.ShipEmail = TextBoxSemail.Text;
        objOrder.ShipAddress = TextBoxSAddress.Text;
        objOrder.ShipPhone = TextBoxSphone.Text;
        objOrder.ShipState = TextBoxSState.Text;
        objOrder.ShipCity = TextBoxScity.Text;
        objOrder.ShipZipCode = TextBoxSzipcode.Text;
        objOrder.PayName = TextBoxPMname.Text;
        objOrder.PayCardType = ddlistCardtype.SelectedItem.Text;
        objOrder.PayCardNum = TextBoxPMcardnum.Text;
        objOrder.PayVeriNum = TextBoxPMverinum.Text;
        objOrder.PayExpri = Convert.ToDateTime(TextBoxPMexpri.Text);
        objOrder.Quantity = Convert.ToInt32(TextBoxquantity.Text);
        objOrder.Totalmoney = Convert.ToDecimal(Texttotalprice.Text);
        objOrder.OdID = ID;

        OrderBus orderBus = new OrderBus();
        orderBus.UpdateOrder(objOrder);
   
        
       
    }
}
